 $ontext
[1]        $model:taxout
[2]        
[3]        $sectors:
[4]          y(s)              ! production
[5]          va(s)             ! value added
[6]          u                 ! utility index
[7]          g                 ! government expenditure
[8]        
[9]        $commodities:
[10]         pd(o)             ! domestic price of commodity
[11]         pva(s)            ! price index for value added
[12]         pf(f)             ! price of primary factor
[13]         pu                ! price index for utility
[14]         pg                ! price of a government output unit
[15]       
[16]       $consumers:
[17]         ra                ! representative agent income
[18]         gov               ! government income
[19]       
[20]       $prod:y(s)          t:etrn(s)
[21]         o:pd(o)           q:supply(s,o)       a:gov          t:bto(s,o)
[22]         i:pd(o)           q:interm(o,s)
[23]         i:pva(s)          q:(sum(f, bpf(f,s)*factor(f,s)))
[24]       
[25]       $prod:va(s)         s:esub(s)
[26]         o:pva(s)          q:(sum(f, bpf(f,s)*factor(f,s)))
[27]         i:pf(f)           q:factor(f,s)       p:bpf(f,s)     a:gov     t:btf(f,s)
[28]       
[29]       $prod:u             s:esubc
[30]         o:pu              q:(sum(o, demand(o)))
[31]         i:pd(o)           q:demand(o)
[32]       
[33]       $prod:g
[34]         o:pg              q:(sum(o, govdem(o)))
[35]         i:pd(o)           q:govdem(o)
[36]       
[37]       $demand:ra
[38]         d:pu
[39]         e:pf(f)           q:endow(f)
[40]       
[41]       $demand:gov
[42]         d:pg
[43]       
[44]       * $report:
[45]       *  v:rsupply(s,o)    o:pd(o)             prod:y(s)
[46]       *  v:rdemand(o)      i:pd(o)             prod:u
[47]       
 $offtext

*   Alert the user to undefined sets or parameters which are referenced in the MPSGE model:

$if not settype s          $abort "s should be a SET."
$if not settype o          $abort "o should be a SET."
$if not settype f          $abort "f should be a SET."
$if not partype supply     $abort "supply should be a PARAMETER."
$if not dimension 2 supply $abort "supply has an inconsistent dimension."
$if not partype bto        $abort "bto should be a PARAMETER."
$if not dimension 2 bto    $abort "bto has an inconsistent dimension."
$if not partype interm     $abort "interm should be a PARAMETER."
$if not dimension 2 interm $abort "interm has an inconsistent dimension."
$if not partype factor     $abort "factor should be a PARAMETER."
$if not dimension 2 factor $abort "factor has an inconsistent dimension."
$if not partype bpf        $abort "bpf should be a PARAMETER."
$if not dimension 2 bpf    $abort "bpf has an inconsistent dimension."
$if not partype btf        $abort "btf should be a PARAMETER."
$if not dimension 2 btf    $abort "btf has an inconsistent dimension."
$if not partype demand     $abort "demand should be a PARAMETER."
$if not dimension 1 demand $abort "demand has an inconsistent dimension."
$if not partype govdem     $abort "govdem should be a PARAMETER."
$if not dimension 1 govdem $abort "govdem has an inconsistent dimension."
$if not partype endow      $abort "endow should be a PARAMETER."
$if not dimension 1 endow  $abort "endow has an inconsistent dimension."

*    Define aliases for sets:

alias (s,s_); 
alias (o,o_); 
alias (f,f_); 

*    Benchmark costs and value shares:

PARAMETER

*    Benchmark costs:

        c0_002(s,o) Benchmark cost for input pd(o) in sector y(s)
        c0_003(s)   Benchmark cost for input pva(s) in sector y(s)
        c0_001(s)   Benchmark cost for input nest s in sector y(s)
        c0_007(s,f) Benchmark cost for input pf(f) in sector va(s)
        c0_006(s)   Benchmark cost for input nest s in sector va(s)
        c0_011(o)   Benchmark cost for input pd(o) in sector u
        c0_010      Benchmark cost for input nest s in sector u
        c0_015(o)   Benchmark cost for input pd(o) in sector g
        c0_014      Benchmark cost for input nest s in sector g

*    Benchmark revenue:

        r0_005(s,o) Benchmark revenue for output pd(o) in sector y(s)
        r0_004(s)   Benchmark revenue for output nest t in sector y(s)
        r0_009(s)   Benchmark revenue for output pva(s) in sector va(s)
        r0_008(s)   Benchmark revenue for output nest t in sector va(s)
        r0_013      Benchmark revenue for output pu in sector u
        r0_012      Benchmark revenue for output nest t in sector u
        r0_017      Benchmark revenue for output pg in sector g
        r0_016      Benchmark revenue for output nest t in sector g

*    Benchmark shares:

        theta_002(s,o) Benchmark share for input  pd(o) in nest s for sector y(s)
        theta_003(s)   Benchmark share for input  pva(s) in nest s for sector y(s)
        theta_005(s,o) Benchmark share for output pd(o) in nest t for sector y(s)
        theta_007(s,f) Benchmark share for input  pf(f) in nest s for sector va(s)
        theta_009(s)   Benchmark share for output pva(s) in nest t for sector va(s)
        theta_011(o)   Benchmark share for input  pd(o) in nest s for sector u
        theta_013      Benchmark share for output pu in nest t for sector u
        theta_015(o)   Benchmark share for input  pd(o) in nest s for sector g
        theta_017      Benchmark share for output pg in nest t for sector g
;



*   Invoke the function preprocessor


$sysinclude gams-f

c0_002(s,o) = interm(o,s);                  
c0_003(s) = (sum(f, bpf(f,s)*factor(f,s))); 
r0_005(s,o) = supply(s,o);                  
c0_001(s) = +sum(o,c0_002(s,o))+c0_003(s);  
r0_004(s) = +sum(o,r0_005(s,o));            
c0_007(s,f) = (factor(f,s))*(bpf(f,s));     
r0_009(s) = (sum(f, bpf(f,s)*factor(f,s))); 
c0_006(s) = +sum(f,c0_007(s,f));            
r0_008(s) = +r0_009(s);                     
c0_011(o) = demand(o);                      
r0_013 = (sum(o, demand(o)));               
c0_010 = +sum(o,c0_011(o));                 
r0_012 = +r0_013;                           
c0_015(o) = govdem(o);                      
r0_017 = (sum(o, govdem(o)));               
c0_014 = +sum(o,c0_015(o));                 
r0_016 = +r0_017;                           
theta_002(s,o) = c0_002(s,o)/c0_001(s); 
theta_003(s) = c0_003(s)/c0_001(s);     
theta_005(s,o) = r0_005(s,o)/r0_004(s); 
theta_007(s,f) = c0_007(s,f)/c0_006(s); 
theta_009(s) = r0_009(s)/r0_008(s);     
theta_011(o) = c0_011(o)/c0_010;        
theta_013 = r0_013/r0_012;              
theta_015(o) = c0_015(o)/c0_014;        
theta_017 = r0_017/r0_016;              

*   Cost functions

p_002(s,o) == pd(o);                                                                                                                                                                              
p_003(s) == pva(s);                                                                                                                                                                               
p_005(s,o) == pd(o) * (1+bto(s,o));                                                                                                                                                               
p_001(s) == sum(o,theta_002(s,o) * p_002(s,o))+theta_003(s)*p_003(s);                                                                                                                             
p_004(s) ==( sum(o,theta_005(s,o) * p_005(s,o)))$(etrn(s)=0) + ( sum(o,theta_005(s,o) * p_005(s,o)**(1-etrn(s)))$(etrn(s)<>1 and etrn(s)<>0 ) + ( prod(o,p_005(s,o)**theta_005(s,o))$(etrn(s)=1); 
p_007(s,f) == pf(f) * (1+btf(f,s))/(bpf(f,s));                                                                                                                                                    
p_009(s) == pva(s);                                                                                                                                                                               
p_006(s) ==( sum(f,theta_007(s,f) * p_007(s,f)))$(esub(s)=0) + ( sum(f,theta_007(s,f) * p_007(s,f)**(1-esub(s)))$(esub(s)<>1 and esub(s)<>0 ) + ( prod(f,p_007(s,f)**theta_007(s,f))$(esub(s)=1); 
p_008(s) == theta_009(s)*p_009(s);                                                                                                                                                                
p_011(o) == pd(o);                                                                                                                                                                                
p_013 == pu;                                                                                                                                                                                      
p_010 ==( sum(o,theta_011(o) * p_011(o)))$(esubc=0) + ( sum(o,theta_011(o) * p_011(o)**(1-esubc))$(esubc<>1 and esubc<>0 ) + ( prod(o,p_011(o)**theta_011(o))$(esubc=1);                          
p_012 == theta_013*p_013;                                                                                                                                                                         
p_015(o) == pd(o);                                                                                                                                                                                
p_017 == pg;                                                                                                                                                                                      
p_014 == sum(o,theta_015(o) * p_015(o));                                                                                                                                                          
p_016 == theta_017*p_017;                                                                                                                                                                         

*   Quantity functions

q_002(s,o) == interm(o,s);                  
q_003(s) == (sum(f, bpf(f,s)*factor(f,s))); 
q_005(s,o) == supply(s,o);                  
q_007(s,f) == factor(f,s);                  
q_009(s) == (sum(f, bpf(f,s)*factor(f,s))); 
q_011(o) == demand(o);                      
q_013 == (sum(o, demand(o)));               
q_015(o) == govdem(o);                      
q_017 == (sum(o, govdem(o)));               

*   Compensated demand indices:

d_001(s) ==  1;                                         
d_002(s,o) == d_001(s)* (p_001(s)/p_002(s,o))**0;       
d_003(s) == d_001(s)* (p_001(s)/p_003(s))**0;           
d_006(s) ==  1;                                         
d_007(s,f) == d_006(s)* (p_006(s)/p_007(s,f))**esub(s); 
d_010 ==  1;                                            
d_011(o) == d_010* (p_010/p_011(o))**esubc;             
d_014 ==  1;                                            
d_015(o) == d_014* (p_014/p_015(o))**0;                 

*   Compensated supply indices:

s_004(s) ==  1;                                         
s_005(s,o) == s_004(s)* (p_004(s)/p_005(s,o))**etrn(s); 
s_008(s) ==  1;                                         
s_009(s) == s_008(s)* (p_008(s)/p_009(s))**0;           
s_012 ==  1;                                            
s_013 == s_012* (p_012/p_013)**0;                       
s_016 ==  1;                                            
s_017 == s_016* (p_016/p_017)**0;                       

*   Endowments:

e_018(f) == endow(f); 


POSITIVE VARIABLES
        y(s)   production
        va(s)  value added
        u      utility index
        g      government expenditure
        pd(o)  domestic price of commodity
        pva(s) price index for value added
        pf(f)  price of primary factor
        pu     price index for utility
        pg     price of a government output unit
        ra     representative agent income
        gov    government income;


EQUATIONS
        prf_y(s)   "production"
        prf_va(s)  "value added"
        prf_u      "utility index"
        prf_g      "government expenditure"
        mkt_pd(o)  "domestic price of commodity"
        mkt_pva(s) "price index for value added"
        mkt_pf(f)  "price of primary factor"
        mkt_pu     "price index for utility"
        mkt_pg     "price of a government output unit"
        inc_ra     "representative agent income"
        inc_gov    "government income";



MODEL taxout / prf_y.y,prf_va.va,prf_u.u,prf_g.g,mkt_pd.pd,mkt_pva.pva,mkt_pf.pf,mkt_pu.pu,mkt_pg.pg,inc_ra.ra,inc_gov.gov/; 

*     Level value assignments
y.l(s) = 1;   
va.l(s) = 1;  
u.l = 1;      
g.l = 1;      
pd.l(o) = 1;  
pva.l(s) = 1; 
pf.l(f) = 1;  
pu.l = 1;     
pg.l = 1;     

*     Zero profit conditions
prf_y(s)..  c0_001(s)*p_001(s) =G= r0_004(s)*p_004(s);
prf_va(s).. c0_006(s)*p_006(s) =G= r0_008(s)*p_008(s);
prf_u..     c0_010*p_010 =G= r0_012*p_012;
prf_g..     c0_014*p_014 =G= r0_016*p_016;

*     Market clearance conditions
mkt_pd(o)..  
             +sum(s,s_005(s,o)*y(s)*q_005(s,o))+sum(s,-d_002(s,o)*y(s)*q_002(s,o))-d_011(o)*u*q_011(o)-d_015(o)*g*q_015(o) =e= 0;
mkt_pva(s).. 
             -d_003(s)*y(s)*q_003(s)s_009(s)*va(s)*q_009(s) =e= 0;
mkt_pf(f)..  
             +sum(s,-d_007(s,f)*va(s)*q_007(s,f)) + e_018(f) =e= 0;
mkt_pu..     
             s_013*u*q_013-ra/pu =e= 0;
mkt_pg..     
             s_017*g*q_017-gov/pg =e= 0;

*     Income definitions
inc_ra..  
          ra =e=+sum((f,pf(f)*endow(f));
inc_gov.. 
          gov =e=
          +sum((s,o),bto(s,o)*s_005(s,o)*y(s)*pd(o))
          +sum((s,f),btf(f,s)*d_007(s,f)*va(s)*pf(f));

*     Auxiliary constraints:
